package com.nars.datastructures;

public class LinkedListControler<E> {

	private LinkedListElement<E> firstElement;
	
	public void insert(E element) {
		LinkedListElement<E> nextElement = new LinkedListElement<E>();
		nextElement.value = element;
		nextElement.next = firstElement;
		firstElement = nextElement;
	}
	
	public E search(int x) {
		int indexCounter = 0;
		LinkedListElement<E> searchedElement = firstElement;
		do {
			if(indexCounter == x-1) {
				return searchedElement.value;
			} else {
				indexCounter++;
				searchedElement = searchedElement.next;
			}			
		} while (indexCounter < x);
		return null;
	}	
}
